package com.pet.server.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.pet.server.domain.entity.Serve;
import com.pet.server.mapper.ServeMapper;
import com.pet.server.service.IServeService;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ServeServiceImpl implements IServeService {
    private final ServeMapper serviceMapper;

    @Override
    public boolean addNewServe(Serve serve) {
        return serviceMapper.insertOrUpdate(serve) > 0;
    }

    @Override
    public boolean delServeSelectiveById(int id) {
        return serviceMapper.deleteById(id) > 0;
    }

    @Override
    public boolean updateServeSelective(Serve serve) {
        return serviceMapper.insertOrUpdate(serve) > 0;
    }

    @Override
    public Page<Serve> getAllServeList(int pageNo, int pageSize, int shopId) {
        QueryWrapper<Serve> qw = new QueryWrapper<>();

        qw.eq("fk_shop_id", shopId);

        Page<Serve> servePage = serviceMapper.selectPage(new Page<>(pageNo, pageSize), qw);

        return servePage;
    }

    @Override
    public Page<Serve> getServeListByServeType(int pageNo, int pageSize, int shopId, String serveType) {
        QueryWrapper<Serve> qw = new QueryWrapper<>();

        qw.eq("fk_shop_id", shopId);
        qw.like("serve_type", serveType);

        Page<Serve> servePage = serviceMapper.selectPage(new Page<>(pageNo, pageSize), qw);

        return servePage;
    }

    @Override
    public Serve getServeSelective(int id) {
        return serviceMapper.selectById(id);
    }

    @Override
    public Page<Serve> getServiceListByTime(int pageNo, int pageSize, int shopId, String startTime, String endTime) {
        QueryWrapper<Serve> qw = new QueryWrapper<>();

        qw.eq("fk_shop_id", shopId);
        qw.between("serve_schedule", startTime, endTime);

        Page<Serve> servePage = serviceMapper.selectPage(new Page<>(pageNo, pageSize), qw);

        return servePage;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
